package com.jinbo.footmessage.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jinbo.footmessage.R;

import de.hdodenhof.circleimageview.CircleImageView;


/**
 * 公共标题栏
 */
public class  TitleBarView extends FrameLayout{

    private RelativeLayout rl_leftHeadLayout; // 左边头像和红点

    private CircleImageView icv_head; // 左边头像
    private ImageView icv_head_back;

    private ImageView iv_redPoint; // 左边红点

    private ImageView iv_leftBack; // 左边返回

    private TextView tv_centerTitle; // 中间标题

    private TextView tv_rightSuccess; // 右边完成

    private ImageView iv_rightGoTo;   // 右边下一步

    private LinearLayout ll_leftBackImageLayout;

    private LinearLayout ll_rightNextImageLayout;

    private LinearLayout ll_rightNextTextLayout;

    private ImageView iv_rightBtnOne;   // 右边第一个按钮

    private ImageView iv_rightBtnTwo;   // 右边第二个按钮

    private RelativeLayout rl_rightMessageLayout; //右边消息按钮

    private ImageView iv_messageBtn; // 右边消息按钮

    private ImageView iv_messageRedPoint; // 右边消息红点按钮


    // 枚举，调用方法用的
    public enum TitleBarEnum {
        icv_head, ll_leftBackImageLayout, ll_rightNextImageLayout, ll_rightNextTextLayout,iv_rightBtnOne,iv_rightBtnTwo,iv_messageBtn;
    }

    public TitleBarView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
        LayoutInflater inflater = LayoutInflater.from(context);
        inflater.inflate(R.layout.fragment_titlebar_view, this);

        initView();
    }

    public void initView(){

        rl_leftHeadLayout = (RelativeLayout) findViewById(R.id.left_head);
        icv_head = (CircleImageView) findViewById(R.id.icv_head);
        icv_head_back=(ImageView)findViewById(R.id.icv_head_back);
        iv_redPoint = (ImageView) findViewById(R.id.iv_red_point);
        iv_leftBack = (ImageView) findViewById(R.id.left_back_image_botton);
        tv_centerTitle = (TextView) findViewById(R.id.center_title);
        tv_rightSuccess = (TextView) findViewById(R.id.right_text_button);
        iv_rightGoTo = (ImageView) findViewById(R.id.right_image_button);

        ll_leftBackImageLayout = (LinearLayout) findViewById(R.id.left_back_layout);
        ll_rightNextImageLayout = (LinearLayout) findViewById(R.id.right_next_image_layout);
        ll_rightNextTextLayout = (LinearLayout) findViewById(R.id.right_next_text_layout);

        iv_rightBtnOne = (ImageView) findViewById(R.id.right_image_button_one);
        iv_rightBtnTwo = (ImageView) findViewById(R.id.right_image_button_two);

        rl_rightMessageLayout = (RelativeLayout) findViewById(R.id.right_message_layout);
        iv_messageBtn = (ImageView) findViewById(R.id.message_icon);
        iv_messageRedPoint = (ImageView) findViewById(R.id.message_red_point);
    }

    //设置左边返回按钮是否显示
    public void setLeftBackButtonIsVisibler(boolean isVisible){

        if(isVisible){
            iv_leftBack.setVisibility(View.VISIBLE);
        }else{
            iv_leftBack.setVisibility(View.GONE);
        }
    }

    //设置左边的头像是否显示
    public void setLeftHeadIsVisibler(boolean isVisible){

        if(isVisible){
            icv_head.setVisibility(View.VISIBLE);
            icv_head_back.setVisibility(View.VISIBLE);
        }else{
            icv_head.setVisibility(View.GONE);
            icv_head_back.setVisibility(View.GONE);
        }
    }

    //设置左边的头像红点是否显示
    public void setLeftHeadRedPointIsVisible(boolean isVisible){

        if(isVisible){
            iv_redPoint.setVisibility(View.VISIBLE);
        }else{
            iv_redPoint.setVisibility(View.GONE);
        }
    }

    //设置左边那些都不显示
    public void setLeftLayoutIsGone(){

        iv_leftBack.setVisibility(View.GONE);
        iv_rightGoTo.setVisibility(View.GONE);
    }

    //设置中间标题的文本
    public void setCenterTitle(String titleString){
        tv_centerTitle.setVisibility(View.VISIBLE);
        tv_centerTitle.setText(titleString);
    }

    //设置右边的文字按钮显示和内容
    public void setRightTextIsVisible(boolean isVisible,String textString){
        if(isVisible){
            tv_rightSuccess.setVisibility(View.VISIBLE);
            tv_rightSuccess.setText(textString);
        }else{
            tv_rightSuccess.setVisibility(View.GONE);
        }
    }

    //设置右边图片按钮显示和样式
    public void setRigthImageIsVisible(boolean isVisible,int id){

        if(isVisible){
            iv_rightGoTo.setVisibility(View.VISIBLE);
            iv_rightGoTo.setBackgroundResource(id);
        }else{
            iv_rightGoTo.setVisibility(View.GONE);
        }
    }

    //设置右边那些都不显示
    public void setRightLayoutIsGone(){

        tv_rightSuccess.setVisibility(View.GONE);
        rl_leftHeadLayout.setVisibility(View.GONE);
    }

    //设置右边第一个按钮的显示和图标
    public void setRightBtnOneIsVisible(boolean isVisible,int drawable){
        if(isVisible){
            iv_rightBtnOne.setVisibility(View.VISIBLE);
            iv_rightBtnOne.setBackgroundResource(drawable);
        }
    }

    //设置右边第二个按钮的显示和图标
    public void setRightBtnTwoIsVisible(boolean isVisible,int drawable){
        if(isVisible){
            iv_rightBtnTwo.setVisibility(View.VISIBLE);
            iv_rightBtnTwo.setBackgroundResource(drawable);
        }
    }

    //设置右边消息按钮的显示和红点是否显示
    public void setRightMessageBtnIsVisible(boolean isMessageBtnVisible,boolean isRedPointVisible){
        if(isMessageBtnVisible){
            rl_rightMessageLayout.setVisibility(View.VISIBLE);
            if(isRedPointVisible){
                iv_messageRedPoint.setVisibility(View.VISIBLE);
            }else{
                iv_messageRedPoint.setVisibility(View.GONE);
            }
        }
    }

    /*public void setIcv(String url, int defImgRes) {
        icv_head.setImageURL(url, defImgRes);
    }*/

    public void setListener(TitleBarEnum e, OnClickListener listener) {
        if (e == TitleBarEnum.icv_head) {
            icv_head.setOnClickListener(listener);
        } else if (e == TitleBarEnum.ll_leftBackImageLayout) {
            ll_leftBackImageLayout.setOnClickListener(listener);
        } else if (e == TitleBarEnum.ll_rightNextImageLayout) {
            ll_rightNextImageLayout.setOnClickListener(listener);
        } else if (e == TitleBarEnum.ll_rightNextTextLayout) {
            ll_rightNextTextLayout.setOnClickListener(listener);
        }else if (e == TitleBarEnum.iv_rightBtnOne) {
            iv_rightBtnOne.setOnClickListener(listener);
        } else if (e == TitleBarEnum.iv_rightBtnTwo) {
            iv_rightBtnTwo.setOnClickListener(listener);
        }else if (e == TitleBarEnum.iv_messageBtn) {
            iv_messageBtn.setOnClickListener(listener);
        }
    }
}
